{% extends "admin/base.html" %}
{% load i18n %}

{% block extrastyle %}
<style type="text/css">
#changelist-filter ul {
    max-height: 300px;
    overflow-y: scroll;
}
.smooth-border {
    border-width: 2px;
    border-radius: 4px;
    color: black;
    border-style: solid;
    padding: 2px;
}
</style>
{% endblock %}
{% block extrahead %}
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
{% endblock %}
{% block title %}{{ title }} | {% trans 'QATrack+ Admin Site' %}{% endblock %}

{% block branding %}
<h1 id="site-name"><a href="{% url 'home' %}" title="QATrack+ Home">{% trans 'QATrack+ administration' %}</a></h1>
{% endblock %}

{% block nav-global %}{% endblock %}

{% block content %}{% endblock %}

{% block footer %}

{{ block.super }}
<script>

    var admin_urls = {
        TEST_SEARCHER: "{% url 'test_searcher' %}",
        TEST_LIST_SEARCHER: "{% url 'test_list_searcher' %}",
        TEST_LIST_CYCLE_SEARCHER: "{% url 'test_list_cycle_searcher' %}",
        TEST_INSTANCE_SEARCHER: "{% url 'test_instance_searcher' %}",
        TEST_LIST_INSTANCE_SEARCHER: "{% url 'test_list_instance_searcher' %}",
        SERVICE_EVENT_SEARCHER: "{% url 'service_event_searcher' %}"
    };

    if (window.django){
        django.jQuery(function(){

            django.jQuery("form").submit(function() {

                if (this.beenSubmitted){
                    return false;
                } else {
                    django.jQuery(this).find("input[type=submit]").val("Submitting...");
                    this.beenSubmitted = true;
                }

            });

            /// override Django strftime
            console.log("Overriding Date.prototype.strftime in admin/base_site.html");
            if (typeof gettext === "undefined"){
              gettext = function(s){return s;};
            }

            if (typeof window.CalendarNamespace !== "undefined"){
              initCalendar();
            }

        });
    }

    window.DYNAMIC_RAW_ID_MOUNT_URL = "{% url "admin:index" %}";

    function initCalendar(){
        window.CalendarNamespace.monthsOfYearShort = [
            gettext("Jan"),
            gettext("Feb"),
            gettext("Mar"),
            gettext("Apr"),
            gettext("May"),
            gettext("Jun"),
            gettext("Jul"),
            gettext("Aug"),
            gettext("Sep"),
            gettext("Oct"),
            gettext("Nov"),
            gettext("Dec")
        ];

        Date.prototype.getShortMonthName = function() {
            return typeof window.CalendarNamespace === "undefined"
                ? this.getTwoDigitMonth()
                : window.CalendarNamespace.monthsOfYearShort[this.getMonth()];
        };

        Date.prototype.strftime = function(format) {
            var fields = {
                B: this.getFullMonthName(),
                b: this.getShortMonthName(),
                c: this.toString(),
                d: this.getTwoDigitDate(),
                H: this.getTwoDigitHour(),
                I: this.getTwoDigitTwelveHour(),
                m: this.getTwoDigitMonth(),
                M: this.getTwoDigitMinute(),
                p: (this.getHours() >= 12) ? 'PM' : 'AM',
                S: this.getTwoDigitSecond(),
                w: '0' + this.getDay(),
                x: this.toLocaleDateString(),
                X: this.toLocaleTimeString(),
                y: ('' + this.getFullYear()).substr(2, 4),
                Y: '' + this.getFullYear(),
                '%': '%'
            };
            var result = '', i = 0;
            while (i < format.length) {
                if (format.charAt(i) === '%') {
                    result = result + fields[format.charAt(i + 1)];
                    ++i;
                }
                else {
                    result = result + format.charAt(i);
                }
                ++i;
            }
            return result;
        };

    }

</script>
{% endblock footer %}
